﻿using System.Collections.Generic;

namespace SBRepository
{
    /// <summary>
    /// Generic entity repository.
    /// </summary>
    /// <typeparam name="TEntity">The type of the entity.</typeparam>
    public interface IRepository<TEntity> : IReadOnlyRepository<TEntity> where TEntity : class, new()
    {
        /// <summary>
        /// Gets the current session.
        /// </summary>
        /// <value>The session.</value>
        ISession Session { get; set; }

        /// <summary>
        /// Determines whether entity is new.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns>
        /// <c>True</c> if entity is new; otherwise, <c>false</c>.
        /// </returns>
        bool IsNew(TEntity entity);

        /// <summary>
        /// Inserts the specified entity to the underlying data source.
        /// </summary>
        /// <param name="entity">Entity to insert.</param>
        void Insert(TEntity entity);

        /// <summary>
        /// Inserts all entities to the underlying data source.
        /// </summary>
        /// <param name="entities">Entities to insert.</param>
        void InsertAll(IEnumerable<TEntity> entities);

        /// <summary>
        /// Updates the specified entity to the underlying data source.
        /// </summary>
        /// <param name="entity">Entity to update.</param>
        void Update(TEntity entity);

        /// <summary>
        /// Updates the specified entity to the underlying data source.
        /// </summary>
        /// <param name="entity">Entity to update.</param>
        /// <param name="isDetached"><c>True</c> if specified entity is detached; otherwise, <c>false</c>.</param>
        void Update(TEntity entity, bool isDetached);

        /// <summary>
        /// Updates all entities to the underlying data source.
        /// </summary>
        /// <param name="entities">Entities to update.</param>
        void UpdateAll(IEnumerable<TEntity> entities);

        /// <summary>
        /// Deletes the specified entity from the underlying data source.
        /// </summary>
        /// <param name="entity">Entity to delete.</param>
        void Delete(TEntity entity);

        /// <summary>
        /// Deletes all entities from the underlying data source.
        /// </summary>
        /// <param name="entities">Entities to delete.</param>
        void DeleteAll(IEnumerable<TEntity> entities);

        /// <summary>
        /// Deletes all entities from the underlying data source.
        /// </summary>
        void DeleteAll();
    }
}
